package com.example.activities;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {

	public final static int REQUEST_NOME = 1;
	public final static String EXTRA_NOME = "com.example.activities.NOME";
	private EditText nome;
	private TextView resposta;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		nome = (EditText) findViewById(R.id.editNome);
		resposta = (TextView) findViewById(R.id.textMainResposta);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	public void sendNome(View view){
		
		Intent i = new Intent(this, ApresentacaoActivity.class);
		
		 PackageManager pack = getPackageManager();
		 if(pack.queryIntentActivities(i, 0).size() > 0){
			 
			 i.putExtra(EXTRA_NOME, nome.getText().toString());
			 startActivityForResult(i, REQUEST_NOME);
			 
		 }
		 
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		
		if(resultCode == RESULT_OK)
			if(requestCode == REQUEST_NOME){
				
				resposta.setText(data.getStringExtra(ApresentacaoActivity.EXTRA_RESPOSTA));
				
			}
		
	}

}
